package com.cma.cmabackend.controller;

import com.cma.cmabackend.entity.Category;
import com.cma.cmabackend.service.CategoryService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    CategoryService categoryService;

    @PostMapping("")
    public Map<String, Object> addCategory(String category) {
        categoryService.addCategory(category);
        Map<String, Object> result = new HashMap<>();
        result.put("success", true);
        return result;
    }

    @GetMapping("")
    public List<Category> getAll() {
        return categoryService.getAll();
    }
}
